const shelljs = require("shelljs")
const { exec, loadYaml, getLogger, writeFile } = require("mill-node-utils")
const { renderFile } = require("swig")
const { resolve } = require("path")

const logger = getLogger();

async function process(pth, cb) {
    const dbPath = ".cache.db"
    const tplPath = resolve(__dirname, "../../../", "templates/sqlite/create_table.swig")
    const locals = loadYaml(pth)
    const sqlCachePath = resolve(".cache/sqlite", locals.tableName + ".sql")
    const sqlStr = renderFile(tplPath, locals)
    const s = await exec(sqlStr, dbPath)
    writeFile(sqlCachePath, sqlStr)
    logger.info("生成建表语句!")
}

module.exports = {
    process
}